Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Using the CAN-FIND function
The
CAN-FINDfunction lets you determine whether a record with certain field values exists, for example as part of field validation.CAN-FINDtakes a buffer name and aWHEREclause just as you would write for aFINDstatement. It returns true if the record exists and false otherwise. Just as with theFINDstatement, theCAN-FINDfunction can identify a unique record satisfying theWHEREclause, or you can include theFIRST(or evenLAST) keyword before the buffer name to determine whether at least one record exists that satisfies theWHEREclause. TheCAN-FINDfunction returns false if more than one record satisfies the selection criteria and you do not include the qualifierFIRSTorLAST.This simple procedure shows two uses of
CAN-FIND:
In the first case, the code looks for Orders whose CustNum field doesn’t match any Customer record. This code would cause an error in the database’s referential integrity.
The second block looks for Customers that have no Orders. This code would probably be a valid condition, since you need to add a Customer before you start adding Orders for it.
As it turns out, the Sports2000 database doesn’t have any invalid Orders without Customers. If you add a few extra Customers to the database that aren’t in the standard database and that don’t have any Orders, the
DISPLAYstatement will show those, as you can see in Figure 21–3.Figure 21–3: Result of CAN-FIND function example
![]()
Why does the Progress 4GL have this function in addition to the
FINDstatement?CAN-FINDcan return true or false simply by looking at the index entries if the selection criteria can be resolved strictly through a single index, without having to retrieve record values. After all, the statement is only asking whether a record exists (that is, if it can be found). It is not retrieving any particular field values.Thus,
CAN-FINDis beneficial and efficient only when you use it to identify records through one or more fields in a single index. IfCAN-FINDhas to retrieve the database records themselves, then you have lost its performance advantage over theFINDstatement.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |